package com.example.picture;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;

public class MyViewGroup extends ViewGroup {  
    public MyViewGroup(Context context) {  
        super(context);  
        this.initOtherComponent(context);  
    }  
    private void initOtherComponent(Context context) {  
        TextView tTitle = new TextView(context);  
        // set id 1  
        tTitle.setId(1);  
        tTitle.setText("CQU");  

		Log.d("addChild", "title");
        this.addView(tTitle); 
        
        MyView surView = new MyView(context);  
        // set id 2  
        surView.setId(2);  
        surView.setSeqStr("1234566");
        this.addView(surView);  

		Log.d("addChild", "surface");
    }  
    @Override  
    protected void onLayout(boolean changed, int l, int t, int r, int b) {  
        int childCount = getChildCount();  
        for (int i = 0; i < childCount; i++) {  
            View child = getChildAt(i);  
            switch (child.getId()) {  
            case 1:  
                // 1 is aBtn  
                Log.d("MyViewGroup", "btn1 setting");  
                child.setVisibility(View.VISIBLE);  
                child.measure(r - l, b - t);  
                child.layout(0, 0, child.getMeasuredWidth(), child  
                        .getMeasuredHeight());  
                break;  
            case 2:  
                // 2 is bBtn  
                Log.d("MyViewGroup", "btn2 setting");  
                child.setVisibility(View.VISIBLE);  
                child.measure(r - l, b - t);  
                child.layout(0, 50, child.getMeasuredWidth(), child  
                        .getMeasuredHeight() + 50);  
                break;  
            default:  
                //  
            }  
        }  
    }  
}  